<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Academy extends MY_Controller {
	function __construct() {
		parent::__construct();
		
		$this->load->model('type_model', '', TRUE);
		$this->load->model('con_common_model', '', TRUE);
		$this->load->model('con_photo_model', '', TRUE);
		$this->load->model('con_team_model', '', TRUE);
		$this->load->model('position_model', '', TRUE);
		$this->load->model('region_model', '', TRUE);
	}
	
	public function index() {
		$data = $this->common();
		$data['menu'] = $this->_get_menu_tabs();
		$data['parent_type'] = $this->parent_type;
		$this->load->view('frontend/layout', $data);
	}
	
	public function common() {
		if ($this->input->is_ajax_request()) {
			$type = $this->input->post("type");
			$request = $this->input->post("request");
			
			eval("\$data = \$this->_" . $type . "(\$type, \$request);");
			
			$data['request'] = $request;
			$this->load->view('frontend/' . $this->parent_type . '/' . $type, $data);
		} else {
			$first_child_menu_tab = $this->type_model->_get_first_child_menu_tab_by_parent_variable($this->parent_type);
			
			$type = $first_child_menu_tab['variable'];
			$request = 'main_page';
			
			eval("\$data = \$this->_" . $type . "(\$type, \$request);");
			
			$data['type'] = $type;
			$data['request'] = $request;
			return $data;
		}
	}
	
	public function _course($type, $request) {
		if ($request == 'main_page') {
			$condition['type'] = $this->type_model->_get_by('variable', $type, 'id', TRUE);
			$data['course'] = $this->con_common_model->search_by_condition($condition);
		} elseif ($request == 'sub_page') {
			$id = $this->input->post("id");
			$data['course'] = $this->con_common_model->_get_by_id($id);
			
			$condition['con_id'] = $id;
			$condition['type'] = $this->type_model->_get_by('variable', $type, 'id', TRUE);
			
			
			$data['pic'] = $this->con_photo_model->search_by_condition($condition);
		}
		return $data;
	}
	
	public function _exchange($type, $request) {
		if ($request == 'main_page') {
			$condition['type'] = $this->type_model->_get_by('variable', $type, 'id', TRUE);
			$data['course'] = $this->con_common_model->search_by_condition($condition);
		} elseif ($request == 'sub_page') {
			$id = $this->input->post("id");
			$data['exchange'] = $this->con_common_model->_get_by_id($id);
			
			$condition['con_id'] = $id;
			$condition['type'] = $this->type_model->_get_by('variable', $type, 'id', TRUE);
			
			
			$data['pic'] = $this->con_photo_model->search_by_condition($condition);
		}
		return $data;
	}
	
	public function _publishing($type, $request) {
		return null;
	}
}